diff options
| author | Adam Soltys <[email protected]> | 2023-02-08 10:13:03 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-08 10:13:03 -0800 |
| commit | 3b7e5e3492684b3d08f37cb078d6eec3fa4da0b2 (patch) | |
| tree | e22c32c9948e4bacfc14bdc8f95a16c557a916e5 /src/routes/(app)/send/invoice/[id]/+page.server.js | |
| parent | 38a1046a92a8f6e3168c5054dc7de2cb3fd8e726 (diff) | |
| download | coinos-ui-3b7e5e3492684b3d08f37cb078d6eec3fa4da0b2.tar.gz coinos-ui-3b7e5e3492684b3d08f37cb078d6eec3fa4da0b2.zip | |
rm uuid route
Diffstat (limited to 'src/routes/(app)/send/invoice/[id]/+page.server.js')
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.js b/src/routes/(app)/send/invoice/[id]/+page.server.js new file mode 100644 index 00000000..6b7823ce --- /dev/null +++ b/src/routes/(app)/send/invoice/[id]/+page.server.js @@ -0,0 +1,30 @@ +import { error, fail, redirect } from '@sveltejs/kit'; +import { btc as asset, auth, get, post } from '$lib/utils'; + +export async function load({ params: { id }, parent }) { + let { user } = await parent(); + + let { amount, address, tip, text, user: recipient } = await get(`/invoice/${id}`); + if (recipient.username === user.username) throw error(500, { message: 'Cannot send to self' }); + if (tip) amount += tip; + return { amount, address, payreq: text, recipient }; +} + +export const actions = { + default: async ({ cookies, request }) => { + try { + let body = Object.fromEntries(await request.formData()); + let { confirmed } = body; + + if (!confirmed) { + return fail(400, { amount, confirm: true }); + } + + await post('/payments', body, auth(cookies)); + } catch (e) { + return fail(400, { message: e.message }); + } + + throw redirect(307, '/sent'); + } +}; |
